package com.zhentao;

import io.minio.MinioClient;
import io.minio.ObjectWriteResponse;
import io.minio.PutObjectArgs;
import io.minio.errors.*;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
public class TestUpload {
    public static void main(String[] args) throws IOException, ServerException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {

        //1.创建minio的客户端
        MinioClient minioClient = MinioClient.builder().credentials("minioadmin", "minioadmin")
                .endpoint("http://172.20.10.132:19000/").build();

        FileInputStream fileInputStream = new FileInputStream("D:\\模板文件\\plugins");

        //2.执行上传操作  0上传的参数
        PutObjectArgs putObjectArgs = PutObjectArgs.builder().bucket("toutiao")  //桶
                .object("plugins")
//                .contentType("text/html")  //文件类型
                //-1 minio在进行文件上传的时候，如果文件太大，会进行分片操作，默认大小是5M
                .stream(fileInputStream, fileInputStream.available(), -1)
                .build();

        //3. 执行上传才走  1 上传
        ObjectWriteResponse response = minioClient.putObject(putObjectArgs);
        System.out.println(response);

    }
}
